<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-02 19:42:06
 * @LastEditTime: 2023-07-03 12:40:57
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Repositories;

use App\Models\FinanceDepartment;



class FinanceDepartmentRepository extends Repositories
    {


    public function __construct(FinanceDepartment $model)
        {
        $this->model = $model;
        }

    protected function getMenuList()
        {
        return $this->model->with(["children"])->where('parent_id', 0)->get();
        }
    public function fuzzySearch($value)
        {
        $value = trim($value);
        $this->where(function ($query) use ($value)
            {
            $query->orWhere("name", "like", "%{$value}%");
            $query->orWhere("code", "like", "%{$value}%");
            });
        }
    public function delete($ids)
        {
        treeListCallBack(
            $this->model
                ->with(['children'])
                ->whereIn("id", $ids)
                ->get(),
            function ($model)
                {
                $model->delete();
                }
        );
        }
    }
